package com.wcj.springboot.controller;


import com.wcj.springboot.entity.User;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.PathVariable;
import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.wcj.springboot.service.IRoomService;
import com.wcj.springboot.entity.Room;
import com.wcj.springboot.common.Result;

import org.springframework.web.bind.annotation.*;


import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wcj
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/room")
public class RoomController {

    @Resource
    private  IRoomService roomService;

    @PostMapping
    public Result saveOrUpdate(@RequestBody Room room){
        return  Result.success(roomService.saveOrUpdate(room));
    }


    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable Integer id){
        return Result.success(roomService.removeById(id));
    }




    @PostMapping("/del/batch")
    public Result removeBatchByIds(@RequestBody List<Integer> ids){
        return Result.success(roomService.removeBatchByIds(ids));
    }


    @GetMapping
    public Result getList(){
        return Result.success(roomService.list());
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(roomService.getById(id));
    }


    @GetMapping("/page")
    public  Result getPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize,
                                @RequestParam(defaultValue = "") String id){
            IPage<Room> page = new Page<>(pageNum, pageSize);
            QueryWrapper<Room> queryWrapper = new QueryWrapper<>();
            if(!"".equals(id)){
            queryWrapper.like("id",id);
            }
            queryWrapper.orderByDesc("id");
            return Result.success(roomService.page(page,queryWrapper));

   }



}

